# coding:utf8
'''
网页生成器
'''

class HtmlOutput():
    def __init__(self):
        # 设置一个列表保存数据
        self.datas = []

    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)

    def output_html(self):
        fout = open("output.html", "w", encoding="utf-8")

        fout.write("<html>")
        fout.write("<head>")
        # 添加页面头标签中的编码格式
        fout.write('<meta http-equiv="content-type" content="text/html;charset=utf-8">')
        fout.write("<body>")
        fout.write("<table>")

        for data in self.datas:
            fout.write("<tr>")

            fout.write("<td>%s</td>" % data['url'])
            fout.write("<td>%s</td>" % data['title'])
            fout.write("<td>%s</td>" % data['summary'])

            fout.write("</tr>")

        fout.write("</table>")
        fout.write("</body>")
        fout.write("</head>")
        fout.write("</html>")